#
# Copyright (C) 1999  Rob Crittenden (rcrit@greyoak.com)
# Copyright (C) 1999,2000  Ross Combs (rocombs@cs.nmsu.edu)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#

prefix		= /home/bnetd
exec_prefix	= ${prefix}

bindir		= ${exec_prefix}/bin
sbindir		= ${exec_prefix}/sbin
mandir		= ${prefix}/man
confdir		= ${prefix}/etc
sharedir	= ${prefix}/var
filesdir	= ${prefix}/var/files
usersdir	= ${prefix}/var/users
userscdbdir	= ${prefix}/var/userscdb
clandir		= ${prefix}/var/clans
teamdir		= ${prefix}/var/teams
bnmaildir	= ${prefix}/var/bnmail
reportsdir	= ${prefix}/var/reports
chanlogsdir	= ${prefix}/var/chanlogs
charinfodir     = ${prefix}/var/charinfo
charsavedir     = ${prefix}/var/charsave
ladderdir       = ${prefix}/var/ladders
statusdir       = ${prefix}/var/status
bak_charsavedir = ${prefix}/var/bak/charsave
bak_charinfodir = ${prefix}/var/bak/charinfo

SRC_SRCDIR	= .
SRC_BINDIR	= ./../bin
SRC_SBINDIR	= ./../sbin
SRC_MANDIR	= ./../man
SRC_CONFDIR	= ./../conf
SRC_SHAREDIR	= ./../files
SRC_SCRIPTDIR	= ./../scripts

SRC_ACDIR	= ${SRC_SRCDIR}/autoconf
SRC_BNETDDIR	= ${SRC_SRCDIR}/bnetd
SRC_D2CSDIR     = ${SRC_SRCDIR}/d2cs
SRC_D2DBSDIR    = ${SRC_SRCDIR}/d2dbs
SRC_BNIUTILSDIR	= ${SRC_SRCDIR}/bniutils
SRC_BNPASSDIR	= ${SRC_SRCDIR}/bnpass
SRC_BNTRACKDDIR	= ${SRC_SRCDIR}/bntrackd
SRC_CLIENTDIR	= ${SRC_SRCDIR}/client
SRC_COMMONDIR	= ${SRC_SRCDIR}/common
SRC_COMPATDIR	= ${SRC_SRCDIR}/compat
SRC_DEBUGDIR	= ${SRC_SRCDIR}/debug
SRC_CDBDIR	= ${SRC_SRCDIR}/tinycdb
SRC_ZLIBDIR     = ${SRC_SRCDIR}/zlib

RMF		= rm -f

RMDIR		= rmdir

ECHO		= echo

SED		= sed

INSTALL		= /usr/bin/install -c
INSTALL_PROGRAM	= ${INSTALL}
INSTALL_DATA	= ${INSTALL} -m 644
INSTALL_SCRIPT	= ${INSTALL}
INSTALL_DIRS	= /usr/bin/install -c -d -m 755

# CC set by configure
# CFLAGS set by configure
CPPFLAGS	= -DHAVE_CONFIG_H   -DWITH_SQL_MYSQL -DBNETD_DEFAULT_CONF_FILE=\"${confdir}/bnetd.conf\" -DD2CS_DEFAULT_CONF_FILE=\"${confdir}/d2cs.conf\" -DD2DBS_DEFAULT_CONF_FILE=\"${confdir}/d2dbs.conf\" -I"${SRC_SRCDIR}"   -I/usr/local/include/mysql -I/usr/local/include
COMPILE		= gcc -g -O2   ${CPPFLAGS} -fno-strict-aliasing -c
#PREPROCESS	= gcc -E ${CPPFLAGS}
LINK		= gcc -g -O2     -L/usr/local/lib/mysql -L/usr/local/lib
LINK_LIBS	=   -lm -lz -lmysqlclient -lboost_thread

PARTS            = bnetd bniutils bnpass bnpcap bnproxy bntrackd client common compat d2cs d2dbs tinycdb zlib

ifeq (,no)
bnetd_SBIN	=
bnetd_CONFS	=
bnetd_OBJECTS	=
else
bnetd_SBIN	= ${SRC_SBINDIR}/bnetd
bnetd_CONFS	= bnetd.conf ad.conf channel.conf realm.conf autoupdate.conf \
		  bnetd_default_user.plain bnetd_default_user.cdb \
		  versioncheck.conf bnmotd.txt bnissue.txt bnmaps.conf \
		  bnxplevel.conf bnxpcalc.conf news.txt command_groups.conf \
		  bnban.conf bnhelp.conf bnalias.conf anongame_infos.conf \
		  tournament.conf topics.conf sql_DB_layout.conf \
		  address_translation.conf supportfile.conf
bnetd_OBJECTS	= ${SRC_BNETDDIR}/main.o \
${SRC_BNETDDIR}/server.o \
${SRC_BNETDDIR}/connection.o \
${SRC_BNETDDIR}/message.o \
${SRC_BNETDDIR}/handle_init.o \
${SRC_BNETDDIR}/handle_bnet.o \
${SRC_BNETDDIR}/handle_file.o \
${SRC_BNETDDIR}/handle_bot.o \
${SRC_BNETDDIR}/handle_telnet.o \
${SRC_BNETDDIR}/handle_irc.o \
${SRC_BNETDDIR}/handle_udp.o \
${SRC_BNETDDIR}/channel.o \
${SRC_BNETDDIR}/channel_conv.o \
${SRC_BNETDDIR}/game.o \
${SRC_BNETDDIR}/anongame.o \
${SRC_BNETDDIR}/command.o \
${SRC_BNETDDIR}/account.o \
${SRC_BNETDDIR}/account_wrap.o \
${SRC_BNETDDIR}/prefs.o \
${SRC_BNETDDIR}/tick.o \
${SRC_BNETDDIR}/file.o \
${SRC_BNETDDIR}/watch.o \
${SRC_BNETDDIR}/ladder.o \
${SRC_BNETDDIR}/ladder_calc.o \
${SRC_BNETDDIR}/adbanner.o \
${SRC_BNETDDIR}/timer.o \
${SRC_BNETDDIR}/tracker.o \
${SRC_BNETDDIR}/ipban.o \
${SRC_BNETDDIR}/game_conv.o \
${SRC_BNETDDIR}/autoupdate.o \
${SRC_BNETDDIR}/helpfile.o \
${SRC_BNETDDIR}/mail.o \
${SRC_BNETDDIR}/anongame_infos.o \
${SRC_BNETDDIR}/anongame_gameresult.o \
${SRC_BNETDDIR}/storage.o \
${SRC_BNETDDIR}/storage_file.o \
${SRC_BNETDDIR}/file_plain.o \
${SRC_BNETDDIR}/file_cdb.o \
${SRC_BNETDDIR}/storage_sql.o \
${SRC_BNETDDIR}/sql_dbcreator.o \
${SRC_BNETDDIR}/sql_pgsql.o \
${SRC_BNETDDIR}/sql_mysql.o \
${SRC_BNETDDIR}/sql_sqlite3.o \
${SRC_BNETDDIR}/sql_odbc.o \
${SRC_BNETDDIR}/runprog.o \
${SRC_BNETDDIR}/realm.o \
${SRC_BNETDDIR}/character.o \
${SRC_BNETDDIR}/udptest_send.o \
${SRC_BNETDDIR}/versioncheck.o \
${SRC_BNETDDIR}/handle_d2cs.o \
${SRC_BNETDDIR}/news.o \
${SRC_BNETDDIR}/irc.o \
${SRC_BNETDDIR}/alias_command.o \
${SRC_BNETDDIR}/command_groups.o \
${SRC_BNETDDIR}/output.o \
${SRC_BNETDDIR}/handle_anongame.o \
${SRC_BNETDDIR}/tournament.o \
${SRC_BNETDDIR}/anongame_maplists.o\
${SRC_BNETDDIR}/clan.o\
${SRC_BNETDDIR}/team.o\
${SRC_BNETDDIR}/topic.o\
${SRC_BNETDDIR}/friends.o\
${SRC_BNETDDIR}/ladder_binary.o \
${SRC_BNETDDIR}/support.o \
${SRC_BNETDDIR}/attrgroup.o \
${SRC_BNETDDIR}/attrlayer.o \
${SRC_BNETDDIR}/cmdline.o \
${SRC_COMMONDIR}/tag.o \
${SRC_COMMONDIR}/hexdump.o \
${SRC_COMMONDIR}/bn_type.o \
${SRC_COMMONDIR}/packet.o \
${SRC_COMMONDIR}/queue.o \
${SRC_COMMONDIR}/util.o \
${SRC_COMMONDIR}/network.o \
${SRC_COMMONDIR}/list.o \
${SRC_COMMONDIR}/eventlog.o \
${SRC_COMMONDIR}/bnettime.o \
${SRC_COMMONDIR}/bnethash.o \
${SRC_COMMONDIR}/bnethashconv.o \
${SRC_COMMONDIR}/addr.o \
${SRC_COMMONDIR}/hashtable.o \
${SRC_COMMONDIR}/give_up_root_privileges.o \
${SRC_COMMONDIR}/token.o \
${SRC_COMMONDIR}/proginfo.o \
${SRC_COMMONDIR}/rlimit.o \
${SRC_COMMONDIR}/fdwatch.o\
${SRC_COMMONDIR}/fdwatch_select.o\
${SRC_COMMONDIR}/fdwatch_poll.o\
${SRC_COMMONDIR}/fdwatch_kqueue.o\
${SRC_COMMONDIR}/fdwatch_epoll.o\
${SRC_COMMONDIR}/trans.o \
${SRC_COMMONDIR}/xalloc.o \
${SRC_COMMONDIR}/rcm.o \
${SRC_COMMONDIR}/conf.o \
${SRC_COMPATDIR}/pdir.o \
${SRC_COMPATDIR}/inet_aton.o \
${SRC_COMPATDIR}/inet_ntoa.o \
${SRC_COMPATDIR}/strdup.o \
${SRC_COMPATDIR}/strerror.o \
${SRC_COMPATDIR}/strtoul.o \
${SRC_COMPATDIR}/strftime.o \
${SRC_COMPATDIR}/strcasecmp.o \
${SRC_COMPATDIR}/strncasecmp.o \
${SRC_COMPATDIR}/strsep.o \
${SRC_COMPATDIR}/psock.o \
${SRC_COMPATDIR}/uname.o \
${SRC_COMPATDIR}/gettimeofday.o \
${SRC_COMPATDIR}/difftime.o \
${SRC_COMPATDIR}/memset.o \
${SRC_COMPATDIR}/memcpy.o \
${SRC_COMPATDIR}/mmap.o \
${SRC_CDBDIR}/cdb_init.o \
${SRC_CDBDIR}/cdb_find.o \
${SRC_CDBDIR}/cdb_findnext.o \
${SRC_CDBDIR}/cdb_seek.o \
${SRC_CDBDIR}/cdb_seq.o \
${SRC_CDBDIR}/cdb_unpack.o \
${SRC_CDBDIR}/cdb_make_add.o \
${SRC_CDBDIR}/cdb_make_put.o \
${SRC_CDBDIR}/cdb_make_find.o \
${SRC_CDBDIR}/cdb_make.o \
${SRC_CDBDIR}/cdb_hash.o \
${SRC_ZLIBDIR}/pvpgn_adler32.o \
${SRC_ZLIBDIR}/pvpgn_deflate.o \
${SRC_ZLIBDIR}/pvpgn_trees.o \
${SRC_ZLIBDIR}/pvpgn_zutil.o
endif

ifeq (no,no)
d2cs_SBIN	=
d2cs_CONFS	=
d2cs_OBJECTS	=
else
d2cs_SBIN       = ${SRC_SBINDIR}/d2cs
d2cs_CONFS	= d2cs.conf d2server.ini address_translation.conf
d2cs_OBJECTS	= ${SRC_D2CSDIR}/main.o \
${SRC_D2CSDIR}/d2gs.o \
${SRC_D2CSDIR}/handle_d2gs.o \
${SRC_D2CSDIR}/serverqueue.o \
${SRC_D2CSDIR}/connection.o \
${SRC_D2CSDIR}/game.o \
${SRC_D2CSDIR}/server.o \
${SRC_D2CSDIR}/handle_init.o \
${SRC_D2CSDIR}/handle_d2cs.o \
${SRC_D2CSDIR}/d2charfile.o \
${SRC_D2CSDIR}/d2charlist.o \
${SRC_D2CSDIR}/xstring.o \
${SRC_D2CSDIR}/gamequeue.o \
${SRC_D2CSDIR}/conf.o \
${SRC_D2CSDIR}/prefs.o \
${SRC_D2CSDIR}/cmdline_parse.o \
${SRC_D2CSDIR}/bnetd.o \
${SRC_D2CSDIR}/handle_bnetd.o \
${SRC_D2CSDIR}/s2s.o \
${SRC_D2CSDIR}/net.o \
${SRC_D2CSDIR}/d2ladder.o \
${SRC_D2CSDIR}/handle_signal.o \
${SRC_COMMONDIR}/hashtable.o \
${SRC_COMMONDIR}/hexdump.o \
${SRC_COMMONDIR}/eventlog.o \
${SRC_COMMONDIR}/list.o \
${SRC_COMMONDIR}/packet.o \
${SRC_COMMONDIR}/bn_type.o \
${SRC_COMMONDIR}/addr.o \
${SRC_COMMONDIR}/util.o \
${SRC_COMMONDIR}/queue.o \
${SRC_COMMONDIR}/network.o \
${SRC_COMMONDIR}/rlimit.o \
${SRC_COMMONDIR}/fdwatch.o\
${SRC_COMMONDIR}/fdwatch_select.o\
${SRC_COMMONDIR}/fdwatch_poll.o\
${SRC_COMMONDIR}/fdwatch_kqueue.o\
${SRC_COMMONDIR}/fdwatch_epoll.o\
${SRC_COMMONDIR}/d2char_checksum.o\
${SRC_COMMONDIR}/trans.o \
${SRC_COMMONDIR}/xalloc.o \
${SRC_COMPATDIR}/inet_aton.o \
${SRC_COMPATDIR}/inet_ntoa.o \
${SRC_COMPATDIR}/strdup.o \
${SRC_COMPATDIR}/strerror.o \
${SRC_COMPATDIR}/strtoul.o \
${SRC_COMPATDIR}/strftime.o \
${SRC_COMPATDIR}/strcasecmp.o \
${SRC_COMPATDIR}/strncasecmp.o \
${SRC_COMPATDIR}/strsep.o \
${SRC_COMPATDIR}/psock.o \
${SRC_COMPATDIR}/uname.o \
${SRC_COMPATDIR}/gettimeofday.o \
${SRC_COMPATDIR}/difftime.o \
${SRC_COMPATDIR}/pdir.o \
${SRC_COMPATDIR}/memset.o \
${SRC_COMPATDIR}/memcpy.o \
${SRC_COMPATDIR}/memmove.o
endif

ifeq (no,no)
d2dbs_SBIN	=
d2dbs_CONFS	=
d2dbs_OBJECTS	=
else
d2dbs_SBIN      = ${SRC_SBINDIR}/d2dbs
d2dbs_CONFS	= d2dbs.conf
d2dbs_OBJECTS	= ${SRC_D2DBSDIR}/main.o \
${SRC_D2DBSDIR}/charlock.o \
${SRC_D2DBSDIR}/d2ladder.o \
${SRC_D2DBSDIR}/dbserver.o \
${SRC_D2DBSDIR}/dbspacket.o \
${SRC_D2DBSDIR}/cmdline_parse.o \
${SRC_D2DBSDIR}/prefs.o \
${SRC_D2DBSDIR}/handle_signal.o \
${SRC_D2DBSDIR}/dbsdupecheck.o \
${SRC_D2CSDIR}/conf.o \
${SRC_D2CSDIR}/xstring.o \
${SRC_COMMONDIR}/list.o \
${SRC_COMMONDIR}/eventlog.o \
${SRC_COMMONDIR}/hexdump.o \
${SRC_COMMONDIR}/bn_type.o \
${SRC_COMMONDIR}/util.o \
${SRC_COMMONDIR}/addr.o \
${SRC_COMMONDIR}/d2char_checksum.o \
${SRC_COMMONDIR}/xalloc.o \
${SRC_COMMONDIR}/network.o \
${SRC_COMMONDIR}/packet.o \
${SRC_COMPATDIR}/psock.o \
${SRC_COMPATDIR}/strerror.o \
${SRC_COMPATDIR}/strsep.o
endif

sbnetd_SBIN	= ${SRC_SBINDIR}/sbnetd
sbnetd_OBJECTS	= ${SRC_DEBUGDIR}/sbnetd.o \
${SRC_COMPATDIR}/strerror.o

bntrackd_SBIN	= ${SRC_SBINDIR}/bntrackd
bntrackd_OBJECTS= ${SRC_BNTRACKDDIR}/bntrackd.o \
${SRC_COMMONDIR}/util.o \
${SRC_COMMONDIR}/list.o \
${SRC_COMMONDIR}/eventlog.o \
${SRC_COMMONDIR}/hexdump.o \
${SRC_COMMONDIR}/xalloc.o \
${SRC_COMPATDIR}/inet_ntoa.o \
${SRC_COMPATDIR}/strerror.o \
${SRC_COMPATDIR}/psock.o \
${SRC_COMPATDIR}/memset.o

bnchat_BIN	= ${SRC_BINDIR}/bnchat
bnchat_OBJECTS	= ${SRC_CLIENTDIR}/bnchat.o \
${SRC_CLIENTDIR}/client.o \
${SRC_CLIENTDIR}/client_connect.o \
${SRC_CLIENTDIR}/udptest.o \
${SRC_COMMONDIR}/packet.o \
${SRC_COMMONDIR}/queue.o \
${SRC_COMMONDIR}/bn_type.o \
${SRC_COMMONDIR}/network.o \
${SRC_COMMONDIR}/eventlog.o \
${SRC_COMMONDIR}/hexdump.o \
${SRC_COMMONDIR}/bnethash.o \
${SRC_COMMONDIR}/bnethashconv.o \
${SRC_COMMONDIR}/util.o \
${SRC_COMMONDIR}/bnettime.o \
${SRC_COMMONDIR}/proginfo.o \
${SRC_COMMONDIR}/xalloc.o \
${SRC_COMPATDIR}/inet_ntoa.o \
${SRC_COMPATDIR}/strerror.o \
${SRC_COMPATDIR}/psock.o \
${SRC_COMPATDIR}/gettimeofday.o \
${SRC_COMPATDIR}/vsnprintf.o \
${SRC_COMPATDIR}/memset.o

bnpass_BIN	= ${SRC_BINDIR}/bnpass
bnpass_OBJECTS	= ${SRC_BNPASSDIR}/bnpass.o \
${SRC_COMMONDIR}/bnethash.o \
${SRC_COMMONDIR}/eventlog.o \
${SRC_COMMONDIR}/hexdump.o \
${SRC_COMPATDIR}/strerror.o

bnftp_BIN	= ${SRC_BINDIR}/bnftp
bnftp_OBJECTS	= ${SRC_CLIENTDIR}/bnftp.o \
${SRC_CLIENTDIR}/client.o \
${SRC_COMMONDIR}/hexdump.o \
${SRC_COMMONDIR}/packet.o \
${SRC_COMMONDIR}/queue.o \
${SRC_COMMONDIR}/bn_type.o \
${SRC_COMMONDIR}/network.o \
${SRC_COMMONDIR}/eventlog.o \
${SRC_COMMONDIR}/bnettime.o \
${SRC_COMMONDIR}/util.o \
${SRC_COMMONDIR}/xalloc.o \
${SRC_COMPATDIR}/inet_ntoa.o \
${SRC_COMPATDIR}/strerror.o \
${SRC_COMPATDIR}/strftime.o \
${SRC_COMPATDIR}/psock.o \
${SRC_COMPATDIR}/gettimeofday.o

bnbot_BIN	= ${SRC_BINDIR}/bnbot
bnbot_OBJECTS	= ${SRC_CLIENTDIR}/bnbot.o \
${SRC_CLIENTDIR}/client.o \
${SRC_COMMONDIR}/packet.o \
${SRC_COMMONDIR}/bn_type.o \
${SRC_COMMONDIR}/network.o \
${SRC_COMMONDIR}/eventlog.o \
${SRC_COMMONDIR}/hexdump.o \
${SRC_COMMONDIR}/util.o \
${SRC_COMMONDIR}/xalloc.o \
${SRC_COMPATDIR}/inet_ntoa.o \
${SRC_COMPATDIR}/strerror.o \
${SRC_COMPATDIR}/psock.o

bnstat_BIN	= ${SRC_BINDIR}/bnstat
bnstat_OBJECTS	= ${SRC_CLIENTDIR}/bnstat.o \
${SRC_CLIENTDIR}/client.o \
${SRC_CLIENTDIR}/client_connect.o \
${SRC_CLIENTDIR}/udptest.o \
${SRC_COMMONDIR}/packet.o \
${SRC_COMMONDIR}/queue.o \
${SRC_COMMONDIR}/bn_type.o \
${SRC_COMMONDIR}/network.o \
${SRC_COMMONDIR}/eventlog.o \
${SRC_COMMONDIR}/hexdump.o \
${SRC_COMMONDIR}/bnethash.o \
${SRC_COMMONDIR}/bnethashconv.o \
${SRC_COMMONDIR}/util.o \
${SRC_COMMONDIR}/bnettime.o \
${SRC_COMMONDIR}/proginfo.o \
${SRC_COMMONDIR}/xalloc.o \
${SRC_COMPATDIR}/inet_ntoa.o \
${SRC_COMPATDIR}/strerror.o \
${SRC_COMPATDIR}/strftime.o \
${SRC_COMPATDIR}/psock.o \
${SRC_COMPATDIR}/gettimeofday.o \
${SRC_COMPATDIR}/memset.o

bnilist_BIN	= ${SRC_BINDIR}/bnilist
bnilist_OBJECTS	= ${SRC_BNIUTILSDIR}/bnilist.o \
${SRC_BNIUTILSDIR}/fileio.o \
${SRC_BNIUTILSDIR}/tga.o \
${SRC_COMPATDIR}/memcpy.o

bni2tga_BIN	= ${SRC_BINDIR}/bni2tga
bni2tga_OBJECTS	= ${SRC_BNIUTILSDIR}/bni2tga.o \
${SRC_BNIUTILSDIR}/fileio.o

bniextract_BIN	= ${SRC_BINDIR}/bniextract
bniextract_OBJECTS= ${SRC_BNIUTILSDIR}/bniextract.o \
${SRC_BNIUTILSDIR}/fileio.o \
${SRC_BNIUTILSDIR}/tga.o \
${SRC_BNIUTILSDIR}/bni.o \
${SRC_COMPATDIR}/memcpy.o

bnibuild_BIN	= ${SRC_BINDIR}/bnibuild
bnibuild_OBJECTS= ${SRC_BNIUTILSDIR}/bnibuild.o \
${SRC_BNIUTILSDIR}/fileio.o \
${SRC_BNIUTILSDIR}/tga.o \
${SRC_BNIUTILSDIR}/bni.o \
${SRC_COMPATDIR}/memcpy.o

tgainfo_BIN	= ${SRC_BINDIR}/tgainfo
tgainfo_OBJECTS	= ${SRC_BNIUTILSDIR}/tgainfo.o \
${SRC_BNIUTILSDIR}/fileio.o \
${SRC_BNIUTILSDIR}/tga.o \
${SRC_COMPATDIR}/memcpy.o

timetest_BIN	= ${SRC_BINDIR}/timetest
timetest_OBJECTS	= ${SRC_DEBUGDIR}/timetest.o \
${SRC_COMMONDIR}/bn_type.o \
${SRC_COMMONDIR}/eventlog.o \
${SRC_COMMONDIR}/hexdump.o \
${SRC_COMMONDIR}/bnettime.o \
${SRC_COMMONDIR}/xalloc.o \
${SRC_COMPATDIR}/strerror.o \
${SRC_COMPATDIR}/gettimeofday.o

listtest_BIN	= ${SRC_BINDIR}/listtest
listtest_OBJECTS	= ${SRC_DEBUGDIR}/listtest.o \
${SRC_COMMONDIR}/list.o \
${SRC_COMMONDIR}/eventlog.o \
${SRC_COMMONDIR}/hexdump.o \
${SRC_COMMONDIR}/xalloc.o \
${SRC_COMPATDIR}/strerror.o \
${SRC_COMPATDIR}/strdup.o

hashtabletest_BIN	= ${SRC_BINDIR}/hashtabletest
hashtabletest_OBJECTS	= ${SRC_DEBUGDIR}/hashtabletest.o \
${SRC_COMMONDIR}/hashtable.o \
${SRC_COMMONDIR}/eventlog.o \
${SRC_COMMONDIR}/hexdump.o \
${SRC_COMMONDIR}/xalloc.o \
${SRC_COMPATDIR}/strerror.o \
${SRC_COMPATDIR}/strdup.o

addrtest_BIN	= ${SRC_BINDIR}/addrtest
addrtest_OBJECTS	= ${SRC_DEBUGDIR}/addrtest.o \
${SRC_COMMONDIR}/addr.o \
${SRC_COMMONDIR}/util.o \
${SRC_COMMONDIR}/list.o \
${SRC_COMMONDIR}/eventlog.o \
${SRC_COMMONDIR}/hexdump.o \
${SRC_COMMONDIR}/xalloc.o \
${SRC_COMPATDIR}/inet_aton.o \
${SRC_COMPATDIR}/inet_ntoa.o \
${SRC_COMPATDIR}/strerror.o \
${SRC_COMPATDIR}/psock.o \
${SRC_COMPATDIR}/memset.o \
${SRC_COMPATDIR}/memcpy.o \
${SRC_COMPATDIR}/strdup.o

cdb_BIN			= ${SRC_BINDIR}/bncdb
cdb_OBJECTS		= ${SRC_CDBDIR}/cdb.o \
${SRC_CDBDIR}/cdb_init.o \
${SRC_CDBDIR}/cdb_find.o \
${SRC_CDBDIR}/cdb_findnext.o \
${SRC_CDBDIR}/cdb_seek.o \
${SRC_CDBDIR}/cdb_seq.o \
${SRC_CDBDIR}/cdb_unpack.o \
${SRC_CDBDIR}/cdb_make_add.o \
${SRC_CDBDIR}/cdb_make_put.o \
${SRC_CDBDIR}/cdb_make_find.o \
${SRC_CDBDIR}/cdb_make.o \
${SRC_CDBDIR}/cdb_hash.o \
${SRC_COMMONDIR}/eventlog.o \
${SRC_COMMONDIR}/hexdump.o \
${SRC_COMMONDIR}/xalloc.o \
${SRC_COMPATDIR}/mmap.o \
${SRC_COMPATDIR}/getopt.o

OBJECTS		= ${bnetd_OBJECTS} ${d2cs_OBJECTS} ${d2dbs_OBJECTS} ${bntrackd_OBJECTS} ${bnchat_OBJECTS} ${bnpass_OBJECTS} ${bnbot_OBJECTS} ${bnftp_OBJECTS} ${bnstat_OBJECTS} ${bnilist_OBJECTS} ${bni2tga_OBJECTS} ${bniextract_OBJECTS} ${bnibuild_OBJECTS} ${tgainfo_OBJECTS} ${timetest_OBJECTS} ${listtest_OBJECTS} ${hashtabletest_OBJECTS} ${addrtest_OBJECTS} ${cdb_OBJECTS}
SBINS           = ${bnetd_SBIN} ${bntrackd_SBIN} ${d2cs_SBIN} ${d2dbs_SBIN}
BINS            = ${bnchat_BIN} ${bnpass_BIN} ${bnftp_BIN} ${bnbot_BIN} ${bnstat_BIN} ${bnilist_BIN} ${bni2tga_BIN} ${bniextract_BIN} ${bnibuild_BIN} ${tgainfo_BIN} ${cdb_BIN}
MAN1S		= bnetd.1 bntrackd.1 bnchat.1 bnpass.1 bnbot.1 bnftp.1 bnstat.1 bnetd.1 bni2tga.1 bnibuild.1 bniextract.1 bnilist.1 tgainfo.1
MAN5S		= bnetd.conf.5 bntext.5 bnmotd.txt.5 bnissue.txt.5 bnnews.txt.5

CONFS		= ${bnetd_CONFS} ${d2cs_CONFS} ${d2dbs_CONFS}

SHARES		= ad000001.smk ad000001.mng ad000004.mng \
		  tos.txt \
		  newbie.save \
		  termsofservice-default.txt termsofservice-enUS.txt \
		  chathelp-war3-default.txt chathelp-war3-enUS.txt \
		  chathelp-war3-frFR.txt chathelp-war3-zhCN.txt chathelp-war3-ruRU.txt \
		  newaccount-default.txt newaccount-enUS.txt

OTHERRM		= ${sbnetd_OBJECTS} ${sbnetd_SBIN} ${timetest_BIN} ${listtest_BIN} ${hashtabletest_BIN} ${addrtest_BIN} ${cdb_BIN} ${SRC_ACDIR}/ansi2knr ${SRC_ACDIR}/ansi2knr.o 
DIRS		= ${SRC_BINDIR} ${SRC_SBINDIR}

# common dependencies can't be expressed this way portably...
#${OBJECTS}: ${SRC_SRCDIR}/Makefile ${SRC_SRCDIR}/config.h ${SRC_COMMONDIR}/version.h ${SRC_COMMONDIR}/setup_before.h ${SRC_COMMONDIR}/setup_after.h ${SRC_ACDIR}/ansi2knr


.PHONY: all
all: .dep  config ${SBINS} ${BINS} ${SRC_CONFDIR}/bnetd.conf ${SRC_CONFDIR}/d2cs.conf ${SRC_CONFDIR}/d2dbs.conf

.PHONY: clean
clean:
	-${RMF} core
	-${RMF} ${OBJECTS}
	-${RMF} ${SBINS}
	-${RMF} ${BINS}
	-${RMF} ${OTHERRM}

.PHONY: distclean
distclean: clean
	-${RMF} ${SRC_CONFDIR}/bnetd.conf
	-${RMF} ${SRC_CONFDIR}/d2cs.conf
	-${RMF} ${SRC_CONFDIR}/d2dbs.conf
	-${RMF} ${SRC_SRCDIR}/config.cache ${SRC_SRCDIR}/config.log
	-${RMF} ${SRC_SRCDIR}/config.status
	-${RMF} ${SRC_SRCDIR}/Makefile ${SRC_SRCDIR}/config.h
	-${RMDIR} ${DIRS}

.PHONY: cvsclean
cvsclean: distclean
	-${RMF} ${SRC_SRCDIR}/configure ${SRC_SRCDIR}/config.h.in

.PHONY: clean-compile
clean-compile: clean all

.PHONY: config
config: .dep ${SRC_SRCDIR}/Makefile ${SRC_SRCDIR}/config.h

${SRC_SRCDIR}/configure: ${SRC_SRCDIR}/configure.in
	@${ECHO} "The configure script is out of date; rebuilding..."
	cd ${SRC_SRCDIR} && autoconf
	@${ECHO} >> ${SRC_SRCDIR}/config.h.in
	@${ECHO} >> $@

${SRC_SRCDIR}/config.h.in: ${SRC_SRCDIR}/configure.in
	@${ECHO} "The config.h.in header is out of date; rebuilding..."
	cd ${SRC_SRCDIR} && autoheader
	@${ECHO} >> $@
	@${ECHO} >> ${SRC_SRCDIR}/configure

${SRC_SRCDIR}/config.status: ${SRC_SRCDIR}/configure
	@${ECHO} "The config.status script is out of date; rechecking..."
	${SRC_SRCDIR}/config.status --recheck
	@${ECHO} >> $@

${SRC_SRCDIR}/config.h: ${SRC_SRCDIR}/config.h.in ${SRC_SRCDIR}/config.status
	@${ECHO} "The config.h header is out of date; rewriting..."
	${SRC_SRCDIR}/config.status
	@${ECHO} >> ${SRC_SRCDIR}/Makefile
	@${ECHO} >> $@

${SRC_SRCDIR}/Makefile: ${SRC_SRCDIR}/Makefile.in ${SRC_SRCDIR}/config.status
	@${ECHO} "The Makefile is out of date; rewriting..."
	${SRC_SRCDIR}/config.status
	@${ECHO} >> ${SRC_SRCDIR}/config.h
	@${ECHO} >> $@

${SRC_BINDIR}:
	${INSTALL_DIRS} $@

${SRC_SBINDIR}:
	${INSTALL_DIRS} $@

.PHONY: bnetd
bnetd: .dep ${bnetd_SBIN}

.PHONY: install
install: .dep install-sbin install-bin install-man install-conf install-share

.PHONY: install-bnetd
install-bnetd: ${bnetd_SBIN}
	${INSTALL_DIRS} ${DESTDIR}/${sbindir}
	@list='${bnetd_SBIN}'; for p in $$list; do \
	  if test -f $$p; then \
	    ${ECHO} " ${INSTALL_PROGRAM} $$p ${DESTDIR}/${sbindir}"; \
	    ${INSTALL_PROGRAM} $$p ${DESTDIR}/${sbindir}; \
	  else :; fi; \
	done

.PHONY: install-sbin
install-sbin: ${SBINS}
	${INSTALL_DIRS} ${DESTDIR}/${sbindir}
	@list='${SBINS}'; for p in $$list; do \
	  if test -f $$p; then \
	    ${ECHO} "  ${INSTALL_PROGRAM} $$p ${DESTDIR}/${sbindir}"; \
	    ${INSTALL_PROGRAM} $$p ${DESTDIR}/${sbindir}; \
	  else :; fi; \
	done

.PHONY: install-bin
install-bin: ${BINS}
	${INSTALL_DIRS} ${DESTDIR}/${bindir}
	@list='${BINS}'; for p in $$list; do \
	  if test -f $$p; then \
	    ${ECHO} "  ${INSTALL_PROGRAM} $$p ${DESTDIR}/${bindir}"; \
	    ${INSTALL_PROGRAM} $$p ${DESTDIR}/${bindir}; \
	  else :; fi; \
	done

.PHONY: install-man
install-man:
	${INSTALL_DIRS} ${DESTDIR}/${mandir} ${DESTDIR}/${mandir}/man1 ${DESTDIR}/${mandir}/man5
	@list='${MAN1S}'; for p in $$list; do \
	  if test -f ${SRC_MANDIR}/$$p; then \
	    ${ECHO} "  ${INSTALL_DATA} ${SRC_MANDIR}/$$p ${DESTDIR}/${mandir}/man1"; \
	    ${INSTALL_DATA} ${SRC_MANDIR}/$$p ${DESTDIR}/${mandir}/man1; \
	  else :; fi; \
	done
	@list='${MAN5S}'; for p in $$list; do \
	  if test -f ${SRC_MANDIR}/$$p; then \
	    ${ECHO} "  ${INSTALL_DATA} ${SRC_MANDIR}/$$p ${DESTDIR}/${mandir}/man5"; \
	    ${INSTALL_DATA} ${SRC_MANDIR}/$$p ${DESTDIR}/${mandir}/man5; \
	  else :; fi; \
	done

.PHONY: install-conf
install-conf: ${SRC_CONFDIR}/bnetd.conf ${SRC_CONFDIR}/d2cs.conf ${SRC_CONFDIR}/d2dbs.conf
	${INSTALL_DIRS} ${DESTDIR}/${confdir}
	@list='${CONFS}'; for p in $$list; do \
	  if test -f ${SRC_CONFDIR}/$$p; then \
	    ${ECHO} "  ${INSTALL_DATA} ${SRC_CONFDIR}/$$p ${DESTDIR}/${confdir}"; \
	    ${INSTALL_DATA} ${SRC_CONFDIR}/$$p ${DESTDIR}/${confdir}; \
	  else :; fi; \
	done

.PHONY: install-share
install-share:
	${INSTALL_DIRS} ${DESTDIR}/${sharedir} ${DESTDIR}/${filesdir} ${DESTDIR}/${usersdir} ${DESTDIR}/${userscdbdir} ${DESTDIR}/${bnmaildir} ${DESTDIR}/${reportsdir} \
	${DESTDIR}/${chanlogsdir} ${DESTDIR}/${charinfodir} ${DESTDIR}/${charsavedir} ${DESTDIR}/${bak_charsavedir} \
	${DESTDIR}/${bak_charinfodir} ${DESTDIR}/${ladderdir} ${DESTDIR}/${statusdir} \
	${DESTDIR}/${clandir} ${DESTDIR}/${teamdir}
	@list='${SHARES}'; for p in $$list; do \
	  if test -f ${SRC_SHAREDIR}/$$p; then \
	    ${ECHO} "  ${INSTALL_DATA} ${SRC_SHAREDIR}/$$p ${DESTDIR}/${filesdir}"; \
	    ${INSTALL_DATA} ${SRC_SHAREDIR}/$$p ${DESTDIR}/${filesdir}; \
	  else :; fi; \
	done
	chmod u+x ${SRC_SCRIPTDIR}/tos.sh
	${SRC_SCRIPTDIR}/tos.sh ${DESTDIR}/${filesdir}

.PHONY: uninstall
uninstall: uninstall-sbin uninstall-bin uninstall-man uninstall-conf uninstall-share

.PHONY: uninstall-sbin
uninstall-sbin:
	@list='${SBINS}'; for p in $$list; do \
	  ${ECHO} "  ${RMF} ${sbindir}/$$p"; \
	  ${RMF} ${sbindir}/$$p; \
	done

.PHONY: uninstall-bin
uninstall-bin:
	@list='${BINS}'; for p in $$list; do \
	  ${ECHO} "  ${RMF} ${bindir}/$$p"; \
	  ${RMF} ${bindir}/$$p; \
	done

.PHONY: uninstall-man
uninstall-man:
	@list='${MAN1S}'; for p in $$list; do \
	  ${ECHO} "  ${RMF} ${mandir}/man1/$$p"; \
	  ${RMF} ${mandir}/man1/$$p; \
	done
	@list='${MAN5S}'; for p in $$list; do \
	  ${ECHO} "  ${RMF} ${mandir}/man5/$$p"; \
	  ${RMF} ${mandir}/man5/$$p; \
	done

.PHONY: uninstall-conf
uninstall-conf:
	@list='${CONFS}'; for p in $$list; do \
	  ${ECHO} "  ${RMF} ${confdir}/$$p"; \
	  ${RMF} ${confdir}/$$p; \
	done

.PHONY: uninstall-share
uninstall-share:
	@list='${SHARES}'; for p in $$list; do \
	  ${ECHO} "  ${RMF} ${sharedir}/$$p"; \
	  ${RMF} ${sharedir}/$$p; \
	done

${SRC_CONFDIR}/bnetd.conf: ${SRC_CONFDIR}/bnetd.conf.in ${SRC_SRCDIR}/config.status
	@${RMF} $@
	${SED} -e "s@/usr/local/var/@${sharedir}/@g" -e "s@/usr/local/etc/@${confdir}/@g" ${SRC_CONFDIR}/bnetd.conf.in > $@

${SRC_CONFDIR}/d2cs.conf: ${SRC_CONFDIR}/d2cs.conf.in ${SRC_SRCDIR}/config.status
	@${RMF} $@
	${SED} -e "s@/usr/local/var/@${sharedir}/@g" -e "s@/usr/local/etc/@${confdir}/@g" ${SRC_CONFDIR}/d2cs.conf.in > $@

${SRC_CONFDIR}/d2dbs.conf: ${SRC_CONFDIR}/d2dbs.conf.in ${SRC_SRCDIR}/config.status
	@${RMF} $@
	${SED} -e "s@/usr/local/var/@${sharedir}/@g" -e "s@/usr/local/etc/@${confdir}/@g" ${SRC_CONFDIR}/d2dbs.conf.in > $@

${SRC_ACDIR}/ansi2knr: ${SRC_ACDIR}/ansi2knr.o
	@${RMF} $@
	${LINK} ${SRC_ACDIR}/ansi2knr.o ${LINK_LIBS} -o $@

${SRC_ACDIR}/ansi2knr.o: ${SRC_ACDIR}/ansi2knr.c
	@${RMF} $@
	${COMPILE} ${SRC_ACDIR}/ansi2knr.c -o $@

SHOWHEADER:
	@echo
	@echo "Using compile command: ${COMPILE}"
	@echo

.cpp.o:
	@${RMF} $@
	@echo "Compiling $*.cpp"
	@${COMPILE} $< -o $@
	@@:
	@@:

.dep:
	${MAKE} dep

dep:
	@${RMF} .dep
	@for a in ${PARTS}; do \
	    echo Dependency check: $$a; \
	    ${COMPILE} -MM `ls $$a/*.c` | sed -e "s@\(.*\)\.o:\(.*\)@$$a\/\1\.o:\2@g" 1>>.dep; \
	done
	
${bnetd_SBIN}: SHOWHEADER ${bnetd_OBJECTS}
	@${INSTALL_DIRS} ${SRC_SBINDIR}
	@${RMF} $@
	@echo "Linking $@"
	@${LINK} ${bnetd_OBJECTS} ${LINK_LIBS} -o $@

${d2cs_SBIN}: SHOWHEADER ${d2cs_OBJECTS}
	@${INSTALL_DIRS} ${SRC_SBINDIR}
	@${RMF} $@
	@echo "Linking $@"
	@${LINK} ${d2cs_OBJECTS} ${LINK_LIBS} -o $@

${d2dbs_SBIN}: SHOWHEADER ${d2dbs_OBJECTS}
	@${INSTALL_DIRS} ${SRC_SBINDIR}
	@${RMF} $@
	@echo "Linking $@"
	@${LINK} ${d2dbs_OBJECTS} ${LINK_LIBS} -o $@

${sbnetd_SBIN}: SHOWHEADER ${sbnetd_OBJECTS}
	@${INSTALL_DIRS} ${SRC_SBINDIR}
	@${RMF} $@
	@echo "Linking $@"
	@${LINK} ${sbnetd_OBJECTS} ${LINK_LIBS} -o $@

${bntrackd_SBIN}: SHOWHEADER ${bntrackd_OBJECTS}
	@${INSTALL_DIRS} ${SRC_SBINDIR}
	@${RMF} $@
	@echo "Linking $@"
	@${LINK} ${bntrackd_OBJECTS} ${LINK_LIBS} -o $@

${bnchat_BIN}: SHOWHEADER ${bnchat_OBJECTS}
	@${INSTALL_DIRS} ${SRC_BINDIR}
	@${RMF} $@
	@echo "Linking $@"
	@${LINK} ${bnchat_OBJECTS} ${LINK_LIBS} -o $@

${bnpass_BIN}: SHOWHEADER ${bnpass_OBJECTS}
	@${INSTALL_DIRS} ${SRC_BINDIR}
	@${RMF} $@
	@echo "Linking $@"
	@${LINK} ${bnpass_OBJECTS} ${LINK_LIBS} -o $@

${bnftp_BIN}: SHOWHEADER ${bnftp_OBJECTS}
	@${INSTALL_DIRS} ${SRC_BINDIR}
	@${RMF} $@
	@echo "Linking $@"
	@${LINK} ${bnftp_OBJECTS} ${LINK_LIBS} -o $@

${bnbot_BIN}: SHOWHEADER ${bnbot_OBJECTS}
	@${INSTALL_DIRS} ${SRC_BINDIR}
	@${RMF} $@
	@echo "Linking $@"
	@${LINK} ${bnbot_OBJECTS} ${LINK_LIBS} -o $@

${bnstat_BIN}: SHOWHEADER ${bnstat_OBJECTS}
	@${INSTALL_DIRS} ${SRC_BINDIR}
	@${RMF} $@
	@echo "Linking $@"
	@${LINK} ${bnstat_OBJECTS} ${LINK_LIBS} -o $@

${bnilist_BIN}: SHOWHEADER ${bnilist_OBJECTS}
	@${INSTALL_DIRS} ${SRC_BINDIR}
	@${RMF} $@
	@echo "Linking $@"
	@${LINK} ${bnilist_OBJECTS} ${LINK_LIBS} -o $@

${bni2tga_BIN}: SHOWHEADER ${bni2tga_OBJECTS}
	@${INSTALL_DIRS} ${SRC_BINDIR}
	@${RMF} $@
	@echo "Linking $@"
	@${LINK} ${bni2tga_OBJECTS} ${LINK_LIBS} -o $@

${bniextract_BIN}: SHOWHEADER ${bniextract_OBJECTS}
	@${INSTALL_DIRS} ${SRC_BINDIR}
	@${RMF} $@
	@echo "Linking $@"
	@${LINK} ${bniextract_OBJECTS} ${LINK_LIBS} -o $@

${bnibuild_BIN}: SHOWHEADER ${bnibuild_OBJECTS}
	@${INSTALL_DIRS} ${SRC_BINDIR}
	@${RMF} $@
	@echo "Linking $@"
	@${LINK} ${bnibuild_OBJECTS} ${LINK_LIBS} -o $@

${tgainfo_BIN}: SHOWHEADER ${tgainfo_OBJECTS}
	@${INSTALL_DIRS} ${SRC_BINDIR}
	@${RMF} $@
	@echo "Linking $@"
	@${LINK} ${tgainfo_OBJECTS} ${LINK_LIBS} -o $@

${timetest_BIN}: SHOWHEADER ${timetest_OBJECTS}
	@${INSTALL_DIRS} ${SRC_BINDIR}
	@${RMF} $@
	@echo "Linking $@"
	@${LINK} ${timetest_OBJECTS} ${LINK_LIBS} -o $@

${listtest_BIN}: SHOWHEADER ${listtest_OBJECTS}
	@${INSTALL_DIRS} ${SRC_BINDIR}
	@${RMF} $@
	@echo "Linking $@"
	@${LINK} ${listtest_OBJECTS} ${LINK_LIBS} -o $@

${hashtabletest_BIN}: SHOWHEADER ${hashtabletest_OBJECTS}
	@${INSTALL_DIRS} ${SRC_BINDIR}
	@${RMF} $@
	@echo "Linking $@"
	@${LINK} ${hashtabletest_OBJECTS} ${LINK_LIBS} -o $@

${addrtest_BIN}: SHOWHEADER ${addrtest_OBJECTS}
	@${INSTALL_DIRS} ${SRC_BINDIR}
	@${RMF} $@
	@echo "Linking $@"
	@${LINK} ${addrtest_OBJECTS} ${LINK_LIBS} -o $@

${cdb_BIN}: SHOWHEADER ${cdb_OBJECTS}
	@${INSTALL_DIRS} ${SRC_BINDIR}
	@${RMF} $@
	@echo "Linking $@"
	@${LINK} ${cdb_OBJECTS} ${LINK_LIBS} -o $@

ifneq ($(wildcard .dep),)
include .dep
endif

# Tell versions (3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
